package com.example.origin.demo.design.bridge;

public class BridgeDemo {


    public static void main(String[] args) {
        Shape circle = new Circle();
        Shape square = new Square();

        circle.draw(new Red());  // 绘制红色的圆形
        square.draw(new Green()); // 绘制绿色的正方形
    }


}


// 抽象部分 - 形状接口
interface Shape {
    void draw(Color color);
}

// 实现部分 - 颜色接口
interface Color {
    void fill();
}

// 具体实现部分 - 颜色实现
class Red implements Color {
    @Override
    public void fill() {
        System.out.println("Filling shape with red color.");
    }
}

class Green implements Color {
    @Override
    public void fill() {
        System.out.println("Filling shape with green color.");
    }
}

// 具体抽象部分 - 形状实现
class Circle implements Shape {
    @Override
    public void draw(Color color) {
        System.out.println("Drawing a circle...");
        color.fill();
    }
}

class Square implements Shape {
    @Override
    public void draw(Color color) {
        System.out.println("Drawing a square...");
        color.fill();
    }
}